package cn.secby.pay.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.secby.common.log.annotation.Log;
import cn.secby.common.log.enums.BusinessType;
import cn.secby.common.security.annotation.RequiresPermissions;
import cn.secby.pay.domain.Trading;
import cn.secby.pay.service.ITradingService;
import cn.secby.common.core.web.controller.BaseController;
import cn.secby.common.core.web.domain.AjaxResult;
import cn.secby.common.core.utils.poi.ExcelUtil;
import cn.secby.common.core.web.page.TableDataInfo;

/**
 * 交易订单Controller
 * 
 * @author shenkunlin
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/trading")
public class TradingController extends BaseController
{
    @Autowired
    private ITradingService tradingService;

    /**
     * 查询交易订单列表
     */
    @RequiresPermissions("pay:trading:list")
    @GetMapping("/list")
    public TableDataInfo list(Trading trading)
    {
        startPage();
        List<Trading> list = tradingService.selectTradingList(trading);
        return getDataTable(list);
    }

    /**
     * 导出交易订单列表
     */
    @RequiresPermissions("pay:trading:export")
    @Log(title = "交易订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Trading trading)
    {
        List<Trading> list = tradingService.selectTradingList(trading);
        ExcelUtil<Trading> util = new ExcelUtil<Trading>(Trading.class);
        util.exportExcel(response, list, "交易订单数据");
    }

    /**
     * 获取交易订单详细信息
     */
    @RequiresPermissions("pay:trading:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tradingService.selectTradingById(id));
    }

    /**
     * 新增交易订单
     */
    @RequiresPermissions("pay:trading:add")
    @Log(title = "交易订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Trading trading)
    {
        return toAjax(tradingService.insertTrading(trading));
    }

    /**
     * 修改交易订单
     */
    @RequiresPermissions("pay:trading:edit")
    @Log(title = "交易订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Trading trading)
    {
        return toAjax(tradingService.updateTrading(trading));
    }

    /**
     * 删除交易订单
     */
    @RequiresPermissions("pay:trading:remove")
    @Log(title = "交易订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(tradingService.deleteTradingByIds(ids));
    }
}
